home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / oper_sys / presto / prest_04.lha / src / sequent / parallel.h < prev    next >
Encoding:
C/C++ Source or Header  |  1989-06-06  |  3.5 KB  |  149 lines

  1. /* $Copyright:    $
  2.  * Copyright (c) 1984, 1985, 1986 Sequent Computer Systems, Inc.
  3.  * All rights reserved
  4.  *  
  5.  * This software is furnished under a license and may be used
  6.  * only in accordance with the terms of that license and with the
  7.  * inclusion of the above copyright notice.   This software may not
  8.  * be provided or otherwise made available to, or used by, any
  9.  * other person.  No title to or ownership of the software is
  10.  * hereby transferred.
  11.  */
  12.  
  13. /* $Header: /crg2/bruces2/rbk/C++/Presto/src/RCS/parallel.h,v 1.2 88/03/24 09:52:47 rbk Exp $
  14.  *
  15.  * parallel.h
  16.  *    Definitions for use in parallel, shared-memory programs.
  17.  */
  18.  
  19. /* $Log:    parallel.h,v $
  20.  * Revision 1.2  88/03/24  09:52:47  rbk
  21.  * #ifdef ns32000 around ALM fuss.  Can't use system version of this file
  22.  * since C++ doesn't understand asm-functions yet.
  23.  * 
  24.  * Revision 1.1  88/03/22  15:26:42  rbk
  25.  * Initial revision
  26.  * 
  27.  */
  28.  
  29. /*
  30.  * A "lock" is a byte of memory, initialized to zero (unlocked).
  31.  */
  32.  
  33. typedef unsigned char    slock_t;        /* 's' for "spin"-lock */
  34.  
  35. #define    L_UNLOCKED    0
  36. #define    L_LOCKED    1
  37.  
  38. /*
  39.  * Was a conditional lock request granted (L_SUCCESS) or denied (L_FAILED)
  40.  */
  41. #define L_FAILED    0
  42. #define L_SUCCESS    1
  43.  
  44. /*
  45.  * A "barrier" allows multiple processes to synchronize by having
  46.  * all of them exit the barrier construct simultaneously.
  47.  *
  48.  * This version assumes <= 255 processes, fits in one 4-byte integer,
  49.  * and is based on spin-locks.
  50.  */
  51.  
  52. typedef struct    {
  53.     slock_t        b_mutex;    /* mutual exclusion */
  54.     unsigned char    b_limit;    /* number participants */
  55.     unsigned char    b_count;    /* state counter */
  56.     unsigned char    b_useno;    /* current use # (state flag) */
  57. } sbarrier_t;                /* 's' for "spin"-barrier */
  58.  
  59.  
  60. #ifndef c_plusplus
  61. /*
  62.  * Other useful declarations.
  63.  */
  64.  
  65. extern    char    *sbrk(), *shsbrk();
  66. extern    char    *shmalloc();
  67.  
  68. #endif
  69.  
  70. #ifdef    ns32000
  71. /*
  72.  * ALM_HASH() is used to hash an address to an ALM offset.
  73.  */
  74.  
  75. #define    ALM_HASH(x)    ((int)(&(x)) & (0xFF << 2))
  76.  
  77. /*
  78.  * S_LOCK() and S_UNLOCK() provide in-line access to locks for C-programs;
  79.  * these can be used in time-criticial situations, at a cost in code size.
  80.  *
  81.  * CAREFUL using S_LOCK(): cc -O -i doesn't do S_LOCK(&x) correctly; need
  82.  * to pass pointer to lock, not address of lock.
  83.  */
  84.  
  85. #define    S_LOCK(lp)    { \
  86.     register char    *lock_alm = &_alm_base[ALM_HASH(*(lp))]; \
  87.     for (;;) { \
  88.         /* Wait for lock to be available */ \
  89.         while (*(lp) == L_LOCKED) \
  90.             continue; \
  91.         /* Grab ALM gate for atomic access to lock */ \
  92.         while (*lock_alm & ALM_LOCKED) \
  93.             continue; \
  94.         /* Can race with others trying to get the lock */ \
  95.         if (*(lp) == L_UNLOCKED) { \
  96.             /* No race (or won it) -- grab the lock */ \
  97.             *(lp) = L_LOCKED; \
  98.             *lock_alm = ALM_UNLOCKED; \
  99.             break; \
  100.         } \
  101.         /* Lost race, try again */ \
  102.         *lock_alm = ALM_UNLOCKED; \
  103.     } \
  104. }
  105.  
  106. #define    S_UNLOCK(lp)    (*(lp) = L_UNLOCKED)
  107.  
  108. /*
  109.  * Various implementation dependent parameters.
  110.  */
  111.  
  112. #define    NBALM        4        /* number bytes per ALM */
  113. #define    ALMSIZE        1024        /* size of our portion of ALMs */
  114.  
  115. #define    ALM_UNLOCKED    0
  116. #define    ALM_LOCKED    1
  117.  
  118. #define    NALMDEVS    64        /* # different ALM's to try for */
  119.  
  120. #define    ADDR_RND    0x800        /* boundary round (text/data/end) */
  121.  
  122. #endif    ns32000
  123.  
  124. /*
  125.  * Convenience definitions.
  126.  */
  127.  
  128. #ifndef    NULL
  129. #define    NULL        0
  130. #endif
  131.  
  132. /*
  133.  * Various globally used data.
  134.  */
  135.  
  136. extern    int    errno;
  137.  
  138. extern    int    _shm_fd;        /* fd for shared data mapped file */
  139. #ifdef    ns32000
  140. extern    char    *_alm_base;        /* virt addr of mapped ALM's */
  141. #endif    ns32000
  142. extern    int    _pgoff;            /* getpagesize() - 1 */
  143.  
  144. /*
  145.  * PGRND() rounds up a value to next page boundary.
  146.  */
  147.  
  148. #define    PGRND(x)    (char *) (((int)(x) + _pgoff) & ~_pgoff)
  149.